package com.zhiyou.util;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

public class PageBean<T> {
	private int pc;//pageCode 当前页数
	private int tr;//TotalRecored 总记录数
	private int ps;//pageSize 每页记录数
//	private int tp;//TotalPage 总页数
	private List<T> beanList;
	private String url;
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public int getPc() {
		return pc;
	}
	public void setPc(int pc) {
		this.pc = pc;
	}
	public int getTr() {
		return tr;
	}
	public void setTr(int tr) {
		this.tr = tr;
	}
	public int getPs() {
		return ps;
	}
	public void setPs(int ps) {
		this.ps = ps;
	}
	//想要获取tp，tr总记录数/ps每页记录数
	public int getTp() {
		int tp = tr / ps;
		return tr%ps==0?tp:tp+1;
	}
	public List<T> getBeanList() {
		return beanList;
	}
	public void setBeanList(List<T> beanList) {
		this.beanList = beanList;
	}
	public PageBean() {
		super();
		// TODO Auto-generated constructor stub
	}
	public PageBean(int pc, int tr, int ps, int tp, List<T> beanList) {
		super();
		this.pc = pc;
		this.tr = tr;
		this.ps = ps;
		this.beanList = beanList;
	}
	@Override
	public String toString() {
		return "PageBean [pc=" + pc + ", tr=" + tr + ", ps=" + ps + ", BeanList=" + beanList + "]";
	}
	public String getUrl(HttpServletRequest request){
		String contextPath = request.getContextPath();
		String servletPath = request.getServletPath();
		String requestPath = request.getQueryString();
		if(requestPath.contains("&pc=")){
			int index = requestPath.indexOf("&pc=");
			requestPath = requestPath.substring(0, index);
		}
		return contextPath+servletPath+"?"+requestPath;
		
	}

}
